package com.jackrain.nea.fc.ps.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * “商品档案接口” FC-->货品网站
 * Mapper
 *
 * @author WSL
 * @create 2018/1/19
 */
@Mapper
public interface ViewCproDistribMapper {

    class SelectPro {
        public String selectProvider(Map map) {
            return new SQL() {
                {
                    SELECT("CP_C_DISTRIB_ID,ECODE,FACTORYCODE,ENAME,PRICECOSTLIST,PRICELIST,CP_C_SUPPLIER_ID,DATEMARKET," +
                            "OWNERENAME,CREATIONDATE,ISACTIVE,REMARK,PROYEAR,PROSEA,SEX,LARGECLASS,SUPBRAND,PROSOURCE,PURNATURE," +
                            "BUYER,PRONATURE,PROMOTIONTYPE,PROLINE,PRICEBAND,MODIFIERENAME,MODIFIEDDATE,TXTDIM2,IMAGE,DETAILDESC");
                    FROM("PS_C_PRO");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1).append(")");
                    WHERE("ID IN " + sb.toString());
                    WHERE("CP_C_DISTRIB_ID<>0");
                }
            }.toString();
        }
    }

    /**
     * 根据param查询条件 查询【人员档案】表
     *
     * @param param
     * @return String
     */
    @SelectProvider(type = SelectPro.class, method = "selectProvider")
    List<HashMap> selectProvider(@Param("list") Object[] param);

    /**
     * 外键关联查询表【CP_C_STOREORG】的ECODE
     *
     * @param distribId
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_STOREORG WHERE ID = #{distribId}")
    String getDistribEcode(Long distribId);

    /**
     * 外键关联查询表【CP_C_STOREORG】的ECODE
     *
     * @param distribId
     * @return
     */
    @Select("SELECT ENAME FROM CP_C_STOREORG WHERE ID = #{distribId}")
    String getDistribEname(Long distribId);

    /**
     * 外键关联查询表【CP_C_SUPPLIER】的ECODE
     *
     * @param supplierId
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_SUPPLIER WHERE ID = #{supplierId}")
    String getSupplierEcode(Long supplierId);

    /**
     * 外键关联查询表【PS_C_PRODIM_ITEM】的ECODE
     *
     * @param proDimId
     * @return
     */
    @Select("SELECT ECODE FROM PS_C_PRODIM_ITEM WHERE ID = #{proDimId}")
    String getProDimEcode(Long proDimId);
}
